package com.java.test.system.registrationtemplate;

import com.java.test.controller.BaseController;
import com.java.test.dto.PageResultDTO;
import com.java.test.dto.ResponseDTO;
import com.java.test.system.dto.LoginAccountInfo;
import com.java.test.system.registrationtemplate.dto.RegistrationTemplateAddDTO;
import com.java.test.system.registrationtemplate.dto.RegistrationTemplateDTO;
import com.java.test.system.registrationtemplate.dto.RegistrationTemplateQueryDTO;
import com.java.test.system.registrationtemplate.dto.RegistrationTemplateUpdateDTO;
import com.java.test.system.registrationtemplate.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Date;
import java.util.List;

/**
 * 注册模板Controller
 *
 * @author lijie1
 * @date 2020/6/29 0029
 */
@Slf4j
@RestController
@RequestMapping("/systemConfig/registrationTemplate")
public class RegistrationTemplateController extends BaseController {
    @Autowired
    RegistrationTemplateService registrationTemplateService;

    /**
     * 查询
     * @return
     */
    @RequestMapping(value = "/selectToList",method = RequestMethod.POST)
    public ResponseDTO<PageResultDTO<RegistrationTemplateVO>> selectByList(@RequestBody @Valid RegistrationTemplateQueryDTO queryDTO) {
        log.debug("----------注册模板列表查询----------");
        return registrationTemplateService.getSelectByList(queryDTO);
    }

    /**
     * 查询地区
     * @return
     */
    @RequestMapping(value = "/selectToListArea",method = RequestMethod.POST)
    public ResponseDTO<List<AreaVO>> selectByListArea() {
        log.debug("----------注册模板地区列表查询----------");
        return registrationTemplateService.selectByListArea();
    }

    /**
     * 查询字段
     * @return
     */
    @RequestMapping(value = "/selectToListField",method = RequestMethod.POST)
    public ResponseDTO<List<FieldVO>> selectByListField(@RequestBody @Valid RegistrationTemplateDTO dto) {
        log.debug("----------注册模板字段列表查询----------");
        return registrationTemplateService.selectByListField(dto);
    }

    /**
     * 查询第三方
     * @return
     */
    @RequestMapping(value = "/selectToListTrilateral",method = RequestMethod.POST)
    public ResponseDTO<List<TrilateralVO>> selectByListTrilateral() {
        log.debug("----------注册模板第三方列表查询----------");
        return registrationTemplateService.selectByListTrilateral();
    }

    /**
     * 查询注册类型
     * @return
     */
    @RequestMapping(value = "/selectToListType",method = RequestMethod.POST)
    public ResponseDTO<List<TypeVO>> selectToListType() {
        log.debug("----------注册模板类型列表查询----------");
        return registrationTemplateService.selectToListType();
    }

    /**
     * 新增
     * @return
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public ResponseDTO<String> save(@RequestBody @Valid RegistrationTemplateAddDTO addDTO, HttpServletRequest request) {
        log.info("----------注册模板添加----------");
        addDTO.setStatus(1);
        addDTO.setCreateTime(new Date());
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "系统管理-注册管理-注册模板添加");
        addDTO.setOperation(user.getLoginAccout());
        return registrationTemplateService.save(addDTO);
    }

    /**
     * 通过id获取数据
     * @param dto
     * @return
     */
    @RequestMapping(value = "/selectById",method = RequestMethod.POST)
    public ResponseDTO<RegistrationTemplateVO> selectById(@RequestBody @Valid RegistrationTemplateDTO dto) {
        log.info("----------注册模板查询----------");
        return registrationTemplateService.selectById(dto.getId());
    }

    /**
     * 通过id修改数据
     * @param updateDTO
     * @return
     */
    @RequestMapping(value = "/updateById",method = RequestMethod.POST)
    public ResponseDTO<String> updateById(@RequestBody @Valid RegistrationTemplateUpdateDTO updateDTO, HttpServletRequest request) {
        log.info("----------注册模板修改----------");
        updateDTO.setModifyTime(new Date());
        updateDTO.setStatus(1);
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "系统管理-注册管理-注册模板修改");
        return registrationTemplateService.updateById(updateDTO);
    }

    /**
     * 通过id更改状态
     * @param updateDTO
     * @return
     */
    @RequestMapping(value = "/updateByIdToStatus",method = RequestMethod.POST)
    public ResponseDTO<String> updateByIdToStatus(@RequestBody @Valid RegistrationTemplateUpdateDTO updateDTO, HttpServletRequest request) {
        log.info("----------通过id更改状态----------");
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "系统管理-注册管理-注册模板删除");
        return registrationTemplateService.updateByIdToStatus(updateDTO);
    }

    /**
     * 通过id删除数据
     * @param dto
     * @return
     */
    @RequestMapping(value = "/deleteById",method = RequestMethod.POST)
    public ResponseDTO<String> deleteById(@RequestBody @Valid RegistrationTemplateDTO dto, HttpServletRequest request) {
        log.info("----------注册模板删除----------");
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "系统管理-注册管理-注册模板删除");
        return registrationTemplateService.deleteById(dto.getId());
    }

}
